package com.bdqn.throwing;

import org.apache.log4j.Logger;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

/**
 * ServiceThrowing
 *
 * @author LILIBO
 * @since 2021-10-19
 */
@Aspect
@Component
public class ServiceThrowing {

    private Logger logger = Logger.getLogger(ServiceThrowing.class);

    /**
     * 异常增强方法，被代理的目标方法发生异常时（可使用RuntimeException e可接收被代理对象的异常）执行
     *
     * @param jp
     * @param e
     */
    @AfterThrowing(pointcut = "execution(* com.bdqn.service..*.*(..))", throwing = "e")
    public void afterThrowing(JoinPoint jp, RuntimeException e) {
        logger.error("============== 调用 " + jp.getSignature().getName() + " 方法时抛出异常 ==============");
        logger.error("异常信息：" + e.getMessage());
    }

}
